/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openams.server.entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author mike
 */
@Entity
@Table(name = "linearassets")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "LinearAsset.findAll", query = "SELECT l FROM LinearAsset l"),
    @NamedQuery(name = "LinearAsset.findByLinearAssetID", query = "SELECT l FROM LinearAsset l WHERE l.linearAssetID = :linearAssetID"),
    @NamedQuery(name = "LinearAsset.findBySectionID", query = "SELECT l FROM LinearAsset l WHERE l.sectionID = :sectionID"),
    @NamedQuery(name = "LinearAsset.findBySectionName", query = "SELECT l FROM LinearAsset l WHERE l.sectionName = :sectionName")})
public class LinearAsset implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "LinearAssetID", nullable = false)
    private Integer linearAssetID;
    @Basic(optional = false)
    @NotNull
    @Column(name = "SectionID", nullable = false)
    private int sectionID;
    @Size(max = 256)
    @Column(name = "SectionName", length = 256)
    private String sectionName;
    @Lob
    @Column(name = "Line")
    private byte[] line;
    @JoinColumn(name = "AssetCategoryID", referencedColumnName = "AssetCategoryID", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private AssetCategory assetCategoryID;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "linearAssetID", fetch = FetchType.LAZY)
    private Collection<LinearAssetAssignment> linearAssetAssignmentCollection;

    public LinearAsset() {
    }

    public LinearAsset(Integer linearAssetID) {
        this.linearAssetID = linearAssetID;
    }

    public LinearAsset(Integer linearAssetID, int sectionID) {
        this.linearAssetID = linearAssetID;
        this.sectionID = sectionID;
    }

    public Integer getLinearAssetID() {
        return linearAssetID;
    }

    public void setLinearAssetID(Integer linearAssetID) {
        this.linearAssetID = linearAssetID;
    }

    public int getSectionID() {
        return sectionID;
    }

    public void setSectionID(int sectionID) {
        this.sectionID = sectionID;
    }

    public String getSectionName() {
        return sectionName;
    }

    public void setSectionName(String sectionName) {
        this.sectionName = sectionName;
    }

    public byte[] getLine() {
        return line;
    }

    public void setLine(byte[] line) {
        this.line = line;
    }

    public AssetCategory getAssetCategoryID() {
        return assetCategoryID;
    }

    public void setAssetCategoryID(AssetCategory assetCategoryID) {
        this.assetCategoryID = assetCategoryID;
    }

    @XmlTransient
    public Collection<LinearAssetAssignment> getLinearAssetAssignmentCollection() {
        return linearAssetAssignmentCollection;
    }

    public void setLinearAssetAssignmentCollection(Collection<LinearAssetAssignment> linearAssetAssignmentCollection) {
        this.linearAssetAssignmentCollection = linearAssetAssignmentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (linearAssetID != null ? linearAssetID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof LinearAsset)) {
            return false;
        }
        LinearAsset other = (LinearAsset) object;
        if ((this.linearAssetID == null && other.linearAssetID != null) || (this.linearAssetID != null && !this.linearAssetID.equals(other.linearAssetID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.openams.server.entity.LinearAsset[ linearAssetID=" + linearAssetID + " ]";
    }
    
}
